function好難


Q1: 請問以下會輸出什麼內容?

let x = y(function z() {
 console.log('I am z') 
})
function y(fn) {
  fn()
  console.log('I am y')
  return fn
}
x()
console.log(y)  
console.log(x)  
console.log(x === y)
answer
I am z
I am y
I am z
[Function: y]
[Function: z]
false

參考文章覺得 JavaScript function 很有趣的我是不是很奇怪








你可能感興趣的文章

Day00 那些年我所不知道的 Web API 們

Day00 那些年我所不知道的 Web API 們

每日心得筆記 2020-07-09(四)

每日心得筆記 2020-07-09(四)

我知道你懂 hoisting,可是你了解到多深?

我知道你懂 hoisting,可是你了解到多深?






留言討論